/**
 * 
 */
package org.vsg.common.web.json.processor;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import net.sf.json.JsonConfig;
import net.sf.json.processors.JsDateJsonValueProcessor;
import net.sf.json.processors.JsonValueProcessor;

/**
 * @author Bill Vison
 *
 */
public class JsDateViewJsonValueProcessor extends JsDateJsonValueProcessor implements JsonValueProcessor {

	private DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	
	/* (non-Javadoc)
	 * @see net.sf.json.processors.JsonValueProcessor#processArrayValue(java.lang.Object, net.sf.json.JsonConfig)
	 */
	@Override
	public Object processArrayValue(Object value, JsonConfig jcf) {
		// TODO Auto-generated method stub
		String[] results = {};
		
		if (value instanceof Date[]) {
			Date[] values = (Date[])value;
			for (int i = 0 ; i < values.length ; i++) {
				results[i] = df.format(values[i]);
			}
		}
		return results;
	}

	/* (non-Javadoc)
	 * @see net.sf.json.processors.JsonValueProcessor#processObjectValue(java.lang.String, java.lang.Object, net.sf.json.JsonConfig)
	 */
	@Override
	public Object processObjectValue(String key, Object value, JsonConfig jcf) {
		// TODO Auto-generated method stub
		String result = null;
		if (value instanceof Date) {
			result = df.format((Date)value  );
		}
		return result;
	}

}
